package com.funo.main.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.springframework.stereotype.Repository;

import com.funo.common.pojo.QueryCondition;
import com.funo.core.base.BaseDao;
import com.funo.main.dao.UserDao;
import com.funo.main.entities.User;

/**
 * 用户管理接口实现类
 * 
 * @author zhengjs
 *
 */
@Repository
public class UserDaoImpl extends BaseDao<User, String> implements UserDao {

	@Override
	public List<User> pageList(QueryCondition condition) {
		Criteria criteria = super.getCriteria();
		criteria.setFirstResult(condition.getStart());
		criteria.setMaxResults(condition.getLimit());
		return super.findByCriteria(criteria);
	}

	@Override
	public Integer count(QueryCondition condition) {
		Criteria criteria = super.getCriteria();
		return super.countByCriteria(criteria);
	}

	@Override
	public User findUser(User user) {
		List<User> list = super.findByExample(user);
		return list.size()==1?list.get(0):null;
	}

	@Override
	public User getUser(String logName) {
		List<User> list = super.findByHql("from User where logName=?", logName);
		return list.size()==1?list.get(0):null;
	}

	@Override
	public User findUserByName(String logName, String id) {
		
		String hql ="from User where logName = ? and id !=?";

		List<User> list =super.findByHql(hql, logName, id);
		
		return list!=null && list.size()>0?list.get(0):null;
	}
}
